package com.haidechizi.leetcode;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author: wangdejun
 * @create: 2020-04-15 10:04
 **/
public class LRUCache {

    private Map<Integer, Integer> map;

    public LRUCache(int capacity) {
        map = new LinkedHashMap<Integer, Integer>(16, 0.75f, true) {
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return capacity < size();
            }
        };
    }

    public int get(int key) {
        Integer result = map.get(key);
        return result == null ? -1 : result;
    }

    public void put(int key, int value) {
        map.put(key, value);
    }
}
